<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="css/element.css" rel="stylesheet"/>
    <link href="css/styleindex.css" rel="stylesheet"/>
    <style>
    .el-input__inner{
      background-color: #fff;
      border: 0;
      font-size: 1rem;
      border-radius: 0;
      padding: 2rem 0;
    }.el-input{
      font-size: 1rem;
    }.el-button{
      background-color: #058142;
      color: #fff;
    }
    </style>
</head>
<body style="background: #F9F9F9;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-lo-bg"></div>
      <div class="x-lo-pro">
        <div class="x-lo-logo"></div>
        <div class="x-lo-tt">餐众邦-CIM系统</div>
        <!--  -->
        <div class="x-lo-form">
          <div class="x-lo-l">
            <el-input placeholder="请输入手机号" prefix-icon="el-icon-user" v-model="name" type="number"></el-input>
          </div>
          <div class="x-lo-l">
            <el-input placeholder="请输入验证码" prefix-icon="el-icon-unlock" v-model="password" type="number"></el-input>
            <div class="x-lo-send" @click="getcode" v-show="codebtn1">发送验证码</div>
            <div class="x-lo-send" @click="getcodetimeover" v-show="codebtn2" v-html="timeoverdatatwo"></div>
            <div class="x-lo-send" @click="getcoderesend" v-show="codebtn3">重新发送</div>
          </div>
          <div class="x-lo-btn">
            <div class="x-lo-lo" @click="gologin">登录</div>
          </div>
        </div>

      </div>
    </div>
  </div>

  <script type="text/javascript" src="./script/vue.js"></script>
  <script type="text/javascript" src="./script/element.js"></script>
  <script type="text/javascript" src="./script/api.js"></script>
  <script type="text/javascript" src="./script/base.js"></script>
	<script>
apiready = function () {
  api.addEventListener({
    name: 'keyback'
  }, function(ret, err) {

  });


    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          name:'',
          password:'',
          loginform:{
            name:'',
            password:''
          },
          codebtn1:true,
          codebtn2:false,
          codebtn3:false,
          timeoverdata:60,
          timeoverdatatwo:'60s',
          isshowiosbtn:false,
          forios:false,

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;

      },
      methods: {
        getcode:function(){
          let that = this;
          that.timeoverdata=60;
          if(that.name==''){
            api.toast({
                msg: '请输入手机号',
                duration: 3000,
                location: 'bottom'
            });
          }else{
            //开始倒计时
            that.getcodetime()
            //开始请求验证码
            that.getcodeajax()
          }
        },
        getcodetime:function(){
          var that = this;
          that.codebtn1 = false;
          that.codebtn2 = true;
          that.codebtn3 = false;
          // that.timeoverdata = that.timeoverdata + 's'
          let myset = setInterval(function(){
            that.timeoverdata--;
            that.timeoverdatatwo = that.timeoverdata + 's'
            // that.timeoverdata = that.timeoverdata + 's'
            // console.log(that.timeoverdata);
            if(that.timeoverdata==0){
              clearInterval(myset)
              that.codebtn1 = false;
              that.codebtn2 = false;
              that.codebtn3 = true;
            }
          },1000)


        },
        setcodeendingtime:function(){
          let that=this;
          timer = setInterval(that.getcodetime(),1000);
        },
        getcodeajax:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/member/sendSms',
            methods:'get',
            data:{
              values:{
                phone: that.name,
                source:'1'
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.toast({
                    msg: '验证码已发送,请注意查看短信',
                    duration: 3000,
                    location: 'bottom'
                });
              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        //60s
        getcodetimeover:function(){
          api.toast({
              msg: '验证码正在路上，请稍等',
              duration: 3000,
              location: 'bottom'
          });
        },
        //重新发送
        getcoderesend:function(){
          let that=this;
          that.timeoverdatatwo = '60s'
          that.getcode()
        },

        gologin:function(){
          let that = this;
          $api.setStorage('applimits','');
          api.closeFrameGroup({
              name: 'openhomecard'
          });
          if(that.name==''||that.password==''){
            api.toast({
                msg: '请输入账号密码',
                duration: 3000,
                location: 'bottom'
            });
          }else{
            api.ajax({
              url:baseurl+'api/member/login',
              methods:'get',
              data:{
                values:{
                  phone: that.name,
                  code:that.password
                }
              }
            },function(ret,err){
              if(ret){
                api.hideProgress();
                // console.log(JSON.stringify(ret));
                if(ret.status == 1){
                  that.name = '';
                  that.password = '';
                  //
                  $api.setStorage('apptoken',ret.data.token_str);
                  $api.setStorage('applimits',ret.data.is_com);//门店0 总部1
                  api.sendEvent({
                      name: 'loginsucc',
                      extra: {
                          key1: 'value1',
                          key2: 'value2'
                      }
                  });
                  //
                  // api.setFrameGroupIndex({
                  //     name: 'openhomecard',
                  //     index: 0
                  // });
                  //
                    api.openWin({
                        name: 'home',
                        url: './home.html',
                        slidBackEnabled:false,
                        pageParam: {

                        }
                    });


                }else{
                  api.toast({
                      msg: ret.msg,
                      duration: 3000,
                      location: 'bottom'
                  });
                }
              }else{
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: err.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            })
          }
        },
      }
    })
	}


	</script>
</body>
</html>
